package com.henushang.ranking.controller.web;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.henushang.ranking.domain.CategoryInfo;
import com.henushang.ranking.domain.RankingData;
import com.henushang.ranking.domain.WebsiteInfo;
import com.henushang.ranking.service.CategoryService;
import com.henushang.ranking.service.RankingDataService;

@Controller
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private RankingDataService rankingDataService;

    @RequestMapping(value = { "/{id}" }, method = RequestMethod.GET)
    public String rankingData(@PathVariable String id, Model model) {
        CategoryInfo categoryInfo = categoryService.getById(id);
        Map<WebsiteInfo, List<RankingData>> rankingData = rankingDataService
                .getRankingDataByCategory(id);
        List<CategoryInfo> navCates = categoryService.getNavCategory();

        model.addAttribute("ci", categoryInfo);
        model.addAttribute("siteRank", rankingData);
        model.addAttribute("nav_cate", navCates);
        return "/category-ranking";
    }
}
